<?php

/**
 * 阿里妈妈报名
 * @desc
 */
class Api_Apply extends PhalApi_Api {



    public function getRules() {
        return [
            'add'  => [
//                'openid' => ['name' => 'openid', 'type' => 'string', 'require' => true, 'desc' => '微信openid'],
                'name'   => ['name' => 'name', 'type' => 'string','max'=>6, 'require' => true, 'desc' => '名字'],
                'tel'    => ['name' => 'tel', 'type' => 'mobile', 'require' => true, 'desc' => '电话'],
                'email'    => ['name' => 'email', 'type' => 'email', 'require' => true, 'desc' => '邮箱'],
                'corp'    => ['name' => 'corp', 'type' => 'string','max'=>20, 'require' => true, 'desc' => '公司名称'],
            ]
        ];
    }



    /**
     * 添加用户资料
     * @desc
     * @return object data 添加后的信息
     */
    function add() {

        $Domain = new Domain_Apply();

        //判断手机号码是否提交过资料

        if (DI()->cache->sIsMember("alimama:tels01", $this->tel)) {
            throw new PhalApi_Exception("已经登记过的手机号码，不能重复登记", 4001);
        }

        return $Domain->addUser($this->name,$this->tel,$this->email,$this->corp);
    }

}